<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ taglib prefix="d" uri="http://dgg.net/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title></title>
    <c:import url="../../header.jsp"/>
</head>
<body>
<div class="content-warp">
    <div class="dgg-list-top-warp">
        <div class="screen-search">
            <ul>
                <li>
                    <label>方案名称：</label>
                    <input type="text" class="dggui-input dggui-input-normal" name="serchPunishName" id="serchPunishName"
                           placeholder="输入方案名称">
                </li>
                <li>
                    <label>状态：</label>
                    <select id="state" name="state" class="dggui-select">
                        <option value="">全部</option>
                        <option value="0">未上架</option>
                        <option value="1">已上架</option>
                    </select>
                </li>
                <li>
                    <label>业态：</label>
                    <input type="text" class="dggui-input dggui-input-normal" readonly value="${ytName}">
                </li>
                <li>
                    <button class="dggui-btn" onclick="tableReload();">搜索</button>
                    <button class="dggui-btn dggui-btn-primary" onclick="cleanSearchPish()">清空条件</button>
                    <%--<button class="dggui-btn dggui-btn-green">导出</button>--%>
                </li>
            </ul>
        </div>
    </div>
    <div class="list-content">
        <div class="tool-bar">
            <div class="fl">
                <a href="javascript:void(0)" class="dggui-btn" onclick="addPunish()">新建方案</a>
            </div>
        </div>
        <div class="table-warp">
            <table class="dggui-table" id="punishScheme">

            </table>
        </div>
    </div>
</div>

<c:import url="/WEB-INF/jsp/footer.jsp"/>
<script>
    var tables;
    dggui.use(['table', 'select2','distpicker'], function (){
        var table = dggui.table;
        var select2 = dggui.select2;
        var distpicker=dggui.distpicker;
        var opt={
            "elem":"#punishScheme",
            "ajax": sysInfo.basePath +"/rzsc/punish/search_all_punish.do",
            "scrollX": "true",//是否开启横项滚动
            //"selectCheck": false, //多选,同时选中复选框
            "oneSelectCheck":true,//单选，同时选中复选框
            "fixedColumns": {//锁定列，只有开启scrollX时才生效
                "leftColumns": 4,//左侧锁定2列
                "rightColumns": 1//右侧锁定1列
            },
            "fnServerParams": function (aoData) {
                //搜索条件
                aoData = $.extend(aoData, {
                    //方案名称
                    name : $("#serchPunishName").val(),
                    //状态
                    state : $('#state').val(),
                    //业态
                    businessTypeCode : "${ytCode}"

                });
                return aoData;
            },
            "aoColumns": [
                {
                    "sClass": "check-th",
                    "orderable": false,
                    "title": "<input type='checkbox'  class='checkall'>",
                    "render": function(data, type, full, meta) {
                        return '<input type="checkbox" class="checkchild" name="checkchild" value="' + data + '">';
                    }
                },
                {
                    "title": "序号",
                    "orderable": false,
                    "render": function(data, type, full, meta) {
                        return meta.row + 1;
                    }
                },
                {
                    'title': '业态',
                    "orderable": false,
                    "data": "businessTypeName",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '方案名称',
                    "orderable": false,
                    "data": "name",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '方案介绍',
                    "orderable": false,
                    "data": "introduce",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '状态',
                    "orderable": false,
                    "data": "state",
                    "render": function (data, type, full, meta) {
                        if(data == 0){
                            return "未上架";
                        }
                        if(data == 1){
                            return "已上架";
                        }
                    }
                },
                {
                    'title': '操作人',
                    "orderable": false,
                    "data": "updaterName",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '操作时间',
                    "orderable": false,
                    "data": "updateTime",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '操作',
                    "orderable": false,
                    "data": "state",
                    "render": function(data, type, row, meta) {
                        var htm = '';
                        if(data == 0){
                            htm = '<a href="javascript:editPunish(\''+row.id+'\',0,\''+row.name+'\')" class="dggui-link">编辑</a>&nbsp;' +
                                '<a href="javascript:updateState(\''+row.id+'\',\''+row.state+'\',1)" class="dggui-link">上架</a>&nbsp;' +
                                '<a href="javascript:updateState(\''+row.id+'\',\''+row.state+'\',2)" class="dggui-link">删除</a>';
                        }
                        if(data == 1){
                            htm =  '<a href="javascript:editPunish(\''+row.id+'\',1,\''+row.name+'\')" class="dggui-link">查看详情</a>&nbsp;'+
                                '<a href="javascript:updateState(\''+row.id+'\',\''+row.state+'\',0)" class="dggui-link">下架</a>';
                        }
                        return htm;
                    }
                }
            ]
        };
        tables = table.render(opt);
        // 处理dataTable 异常错误信息
        $.fn.dataTable.ext.errMode = 'none';//不抛出异常
        tables.on( 'error.dt', function ( e, settings, techNote, message ) {
            //dggui.dialog.errors("表格查询错误，请联系管理员", 2000);
           if(checkEmpty(settings.jqXHR.responseJSON.error)){dggui.dialog.errors(settings.jqXHR.responseJSON.error, 2000);}
        });
    });
    function addPunish(){
        dggui.dialog.loading();
        $.ajax({
            url: sysInfo.basePath+"/rzsc/punish/add_punish_tabpage.html",
            dataType:'html',
            success:function (res){
                dggui.dialog.loading('close');
                dggui.dialog.open({
                    title: '新建方案',
                    content: res,
                    area: ["480px","350px"],
                    btn: ["确定", "取消"],
                    yes: function (index) {
                        punishCreate(index);
                    }, btn2: function () {
                    }
                })
            }
        });
    }
    function updateState(id,oldState,newState){
        var notice = "";
        if(newState == 0){
            notice = "确定下架吗？";
        }
        if(newState == 1){
            notice = "确定上架吗？";
        }
        if(newState == 2){
            notice = "确定删除吗？";
        }
        layer.confirm(notice, {icon: 3, title:'提示'}, function(index){
            dggui.dialog.loading();
            $.post(sysInfo.basePath+"/rzsc/punish/update_punish.do", {id:id,state:newState,oldState:oldState}, function (result) {
                dggui.dialog.loading('close');
                if(result.code == 0){
                    dggui.dialog.succeed('操作成功！');
                    reloadTable($('#punishScheme'),"reload");
                }else{
                    dggui.dialog.errors(result.msg);
                }
            })
            layer.close(index);
        })
    }
    function editPunish(id,type,name){
        /*dggui.dialog.loading();
        $.ajax({
            url: sysInfo.basePath+"/rzsc/punish/edit_punish_tabpage.html",
            data:{id:id,type:type},
            dataType:'html',
            success:function (res){
                dggui.dialog.loading('close');
                dggui.dialog.open({
                    title: '编辑方案',
                    content: res,
                    area: '500px',
                    btn: ["保存", "取消"],
                    yes: function (index) {
                        punishEdit(index);
                    }, btn2: function () {
                    }
                })
            }
        });*/
        var title = type == 1 ? "扣罚方案详情:"+name : "扣罚方案编辑:"+name;
        title = title.replace("<","&lt;");
        title = title.replace(">","&gt;");
        window.parent.updateTab(title,sysInfo.basePath+"/rzsc/punish/edit_punish_tabpage.html?id="+id+"&type="+type);
    }
    //列表刷新
    function tableReload() {
        tables.ajax.reload();
        //$("#allOrderList").dataTableExtend('reload');
    }
    function cleanSearchPish(){
        $("#serchPunishName").val("");
        $("#state").val("");
    }
</script>
</body>
</html>